Skip to content

fix: validate column names with snake_case and camelCase support#94

Merged
ren0503 merged 1 commit into
masterfrom
fix/ren/93-validate-column-snake_case
Jan 19, 2026
Merged

fix: validate column names with snake_case and camelCase support#94
ren0503 merged 1 commit into
masterfrom
fix/ren/93-validate-column-snake_case

Conversation

@ren0503

@ren0503 ren0503 commented Jan 19, 2026

Copy link
Copy Markdown
Contributor
  • Replace validator.IsAlphanumeric with regex pattern for column validation
  • Support snake_case columns (e.g., employee_id, created_at)
  • Support camelCase columns (e.g., firstName, lastName)
  • Support qualified table.column format
  • Add test cases for valid column name patterns

- Replace validator.IsAlphanumeric with regex pattern for column validation
- Support snake_case columns (e.g., employee_id, created_at)
- Support camelCase columns (e.g., firstName, lastName)
- Support qualified table.column format
- Add test cases for valid column name patterns
@ren0503 ren0503 added this to the SQL ORM Release v2.5.1 milestone Jan 19, 2026
@ren0503 ren0503 linked an issue Jan 19, 2026 that may be closed by this pull request
@coderabbitai

coderabbitai Bot commented Jan 19, 2026

Copy link
Copy Markdown

Summary by CodeRabbit

  • Bug Fixes

    • Enhanced SQL column validation to properly support qualified table.column format and snake_case identifiers while enforcing stricter rules that reject invalid patterns including numbers at the start or consecutive dots.
  • Tests

    • Added extensive test coverage for column name validation including dedicated tests for snake_case identifiers, qualified table.column formats, and invalid pattern rejection to ensure robust validation across all scenarios.

✏️ Tip: You can customize this high-level summary in your review settings.

Walkthrough

Replaces external validator dependency with Go's built-in regexp package for SQL column name validation. Updates isValidColumn function to use regex pattern matching that supports optional table.column format, alongside expanded test coverage for snake_case and qualified column names.

Changes

Cohort / File(s) Summary
SQL Column Validation Refactoring
builder.go
Removes external validator dependency; adds validColumnRegex pattern using regexp.MustCompile() to validate SQL column names with optional table.column format; updates isValidColumn() to use regex matching instead of IsAlphanumeric() check.
Validation Test Expansion
builder_test.go
Extends Test_IsValidColumn with new invalid cases ("1column", ".column", "table.", "table..column"); adds ValidColumn_SnakeCase test block for identifiers like employee_id, created_at; adds ValidColumn_QualifiedName test block for qualified names like table.column, users.id.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • #87 — Modifies column-name validation logic in builder.go with isValidColumn changes and associated test expansions.

Poem

🐰✨ A rabbit hops through regex lines,
Where table.column now shines,
No more external tools to keep,
Just patterns woven, tested deep!

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title directly addresses the main change: replacing alphanumeric validation with regex that supports snake_case and camelCase column names, which aligns with the core modifications in builder.go and test coverage.
Description check ✅ Passed The description clearly outlines the changeset: replacing validator.IsAlphanumeric with regex, adding support for snake_case and camelCase columns, supporting qualified names, and adding test cases—all of which are present in the actual changes.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.5.0)

Error: can't load config: unsupported version of the configuration: "" See https://golangci-lint.run/docs/product/migration-guide for migration instructions
The command is terminated due to an error: can't load config: unsupported version of the configuration: "" See https://golangci-lint.run/docs/product/migration-guide for migration instructions


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@ren0503 ren0503 merged commit 23863d7 into master Jan 19, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

isValidColumn returns false for snake_case columns like employee_id

2 participants